<template>
  <div class="page-main" v-title data-title="清洗方式主数据">
    <home-nav :userData="userinfo"></home-nav>
    <div class="banner"><span>清洗方式主数据</span></div>
    <div class="container">
      <div class="container-bg">
        <div class="header">
          <a-row type="flex" justify="space-between" align="middle">
            <a-col :xl="{ span: 11 }" :lg="{ span: 11 }">
              <a-button class="hte-btn add-btn" type="primary" icon="plus" @click="handAction('add')">新增</a-button>
              <a-button class="hte-btn" @click="handAction('upd')">修改</a-button>
              <a-button class="hte-btn" type="danger" @click="handAction('del')">删除</a-button>
              <a-button class="hte-btn" @click="refresh">刷新</a-button>
            </a-col>
            <a-col :xl="{ span: 9 }" :lg="{ span: 13 }" class="input-ground">
              <a-input-group compact>
                <a-select v-model="searchField" @change="changeKeywordType">
                  <a-select-option value="wayNoStr"> 方式编号 </a-select-option>
                  <a-select-option value="wayName"> 方式名称 </a-select-option>
                </a-select>
                <a-input-search
                  v-if="searchField == 'wayNoStr'"
                  v-model="queryParam.wayNoStr"
                  @search="doSearch"
                  allowClear
                  placeholder="请输入关键词检索"
                />
                <a-input-search
                  v-if="searchField == 'wayName'"
                  v-model="queryParam.wayName"
                  @search="doSearch"
                  allowClear
                  placeholder="请输入关键词检索"
                />
              </a-input-group>
              <a-button class="hte-btn del-btn" @click="visibleModel = true">高级查询</a-button>
            </a-col>
          </a-row>
        </div>
        <div class="content">
          <a-table
            class="hte-table-content"
            :scroll="{ x: 840 }"
            :columns="columns"
            :data-source="dataSource"
            :pagination="ipagination"
            :loading="loading"
            :row-selection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }"
            rowKey="id"
            size="middle"
            @change="handleTableChange"
          >
            <template slot="wayNo" slot-scope="text, record">
              <span class="clickspan" @click="handAction('upd', record.id)">{{ text }}</span>
            </template>
          </a-table>
        </div>
      </div>
    </div>
    <a-back-top class="backtodom" />
    <!-- 高级查询 -->
    <advanced-search
      :dataForm.sync="queryParam"
      :visible="visibleModel"
      ref="advanced"
      :formCol="queryParamCol"
      @ok="callBackResult"
      @reset="resetResulte"
      @close="closeResulte"
    >
    </advanced-search>
    <!-- 新增/修改 -->
    <MethodAddModal ref="methodAdd" :washType="washType" @ok="doSearch"></MethodAddModal>
  </div>
</template>
<script>
import Vue from 'vue'
import { getAction, postAction } from '@/api/manage'
import { JeecgListMixin } from '@/mixins/JeecgListSearchMixin'
import { USER_INFO } from '@/store/mutation-types'
import { ClearLibMixin } from '@/mixins/ClearLibMixin'
export default {
  name: 'BurdenList',
  mixins: [ClearLibMixin,JeecgListMixin],
  components: {
    HomeNav: () => import('@/components/layouts/HomeNav'),
    AdvancedSearch: () => import('@/components/tools/AdvancedSearch'),
    MethodAddModal: () => import('./methodAddModal'),
  },
  data() {
    return {
      disableMixinCreated:true,
      userinfo: {
        info: this.$store.getters.userInfo,
        module: 'MethodList',
      },
      currUser: Vue.ls.get(USER_INFO).username,
      columns: [
        {
          title: '方式编号',
          dataIndex: 'wayNoStr',
          width: 120,
          align: 'center',
          scopedSlots: { customRender: 'wayNo' },
        },
        { title: '代码', dataIndex: 'wayCode', width: 120, align: 'center',},
        { title: '清洗方式名称', dataIndex: 'wayName', width: 180, align: 'center' },        
        { title: '方式描述', dataIndex: 'wayDesc', width: 120, align: 'center', ellipsis: true },        
        { title: '创建人', dataIndex: 'createUserName', width: 120, align: 'center' },
        { title: '创建时间', dataIndex: 'createTime', width: 180, align: 'center' },        
      ],
      url: {
        list: '/hteWashWay/page', // 搜索
        delBatch: '/hteWashWay/delBatch', // 删除                
      },
      // 高级查询
      visibleModel: false,
      searchField: 'wayNoStr',
      queryParam: {
        wayNoStr: '',
        wayName: '',
      },
      queryParamCol: [
        { type: 'input', model: 'wayNoStr', label: '方式编号' },
        { type: 'input', model: 'wayName', label: '方式名称' },
      ],
    }
  },
  created(){
     this.loadData(1);

  },
  mounted() {},
  methods: {
    refresh() {
      this.loadData()
    },
    doSearch() {
      this.loadData(1)
    },
    changeKeywordType() {
      if (this.searchField == 'wayNoStr') {
        this.$set(this.queryParam, 'wayName', '')
      } else {
        this.$set(this.queryParam, 'wayNoStr', '')
      }
    },
    /**
     * 高级搜索
     */
    callBackResult() {
      this.visibleModel = false
      this.doSearch()
    },
    closeResulte() {
      this.visibleModel = false
    },
    resetResulte() {
      this.queryParam = {}
    },
    /**
     * 操作
     */
    handAction(type, id) {
      switch (type) {
        case 'add':
          // 新增
          this.$refs.methodAdd.showVisible()
          break
        case 'del':
          // 删除，可多选
          const that = this
          if (this.selectedRowKeys.length == 0) {
            this.$message.warning('请选择至少一条数据！')
            return
          }
          this.$confirm({
            title: '确认删除',
            content: '请确认是否删除此信息?',
            onOk: function () {
              postAction(that.url.delBatch, that.selectedRowKeys).then((res) => {
                if (res.code == 200) {
                  that.$message.success('删除成功')
                  that.loadData();
                } else {
                  that.$message.warning('删除失败:' + res.message)
                }
              })
            },
          })
          break
        case 'upd':
          if(id){
            this.$refs.methodAdd.showVisible(id)
          }else{
            // 修改
            if (this.selectedRowKeys.length != 1) {
              this.$message.warning('请选择一条数据！')
              return
            }
            this.$refs.methodAdd.showVisible(this.selectionRows[0].id)
          }
          break
        default:
          break
      }
    },    
  },
}
</script>

<style lang="less" scoped>
@import '~@assets/less/hte-main.less';
@import '~@views/library/clearSoln/index.less';
</style>
